package web.test.zuul;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;
import web.test.exception.BizException;
import web.test.exception.ErrorCode;

/**
 * @author: Kay.Li Muzi
 * @create: 2021-08-05 11:58
 **/
@Component
public class AuthFilter extends ZuulFilter {
    @Override
    public String filterType() {
        return FilterConstants.PRE_TYPE;
    }

    @Override
    public int filterOrder() {
        return 0;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() throws ZuulException {
        System.out.println("filter运行");
        RequestContext currentContext = RequestContext.getCurrentContext();
        doSomething();
        return null;
    }

    private void doSomething() throws BizException {
        //throw new BizException(ErrorCode.NoRegistry);
        throw new NullPointerException();
    }
}
